from conftest import client
from config import WORK_CASH_GIVE
from utils.models.user import DEFAULT_USER_CASH

MAIN_USER_ID = 1


async def test_me():
    KEYS = ("id", "name", "time_create", "cash",
            "residence", "strength", "education")

    resp = client.get("/users/me")
    data = resp.json()

    assert resp.status_code == 200
    assert tuple(data.keys()) == KEYS
    assert data["cash"] == DEFAULT_USER_CASH


async def test_get_user():
    KEYS = ("id", "name", "time_create",
            "residence", "strength", "education")

    resp = client.get(f"users/get_user/{MAIN_USER_ID}")
    data = resp.json()

    assert resp.status_code == 200
    assert tuple(data.keys()) == KEYS
    assert data["id"] == 1


async def test_get_all_users():
    resp = client.get("users/get_all_users")
    data = resp.json()

    assert resp.status_code == 200
    assert len(data) == 1

    resp_me = client.get(f"users/get_user/{MAIN_USER_ID}")

    assert data[0] == resp_me.json()


async def test_work():
    resp = client.post("users/work")
    data = resp.json()

    assert resp.status_code == 200
    assert data == {"user_reward": WORK_CASH_GIVE, "state_reward": 0}

    resp_me = client.get("users/me")

    assert resp_me.json()["cash"] == DEFAULT_USER_CASH + WORK_CASH_GIVE
